In object-oriented software applications, such as those using Java™, C++ and C# or other object-oriented programming languages, escape analysis determines whether objects instantiated during a method invocation or thread execution persist longer than the invocation or thread itself. This information is useful for various optimizations of the software, such as stack allocation of objects or lock elision.
In Java™, the lifetime of an object is determined by a concept known as reachability. If an object can be reached by an element of a running program, whether it is a static field or the call stack of a thread, or some other construct that maintains references to objects, then the object is live; otherwise, the lifetime of the object has ended.
Escape analysis involves tracking the lifetime of an object, which requires that the reachability of the object within the program at different times must be determined. A central issue is whether an object will remain reachable following the occurrence of a given event, and the most common events in question are method invocations (stream of instructions) or threads (stream of execution). When an object is known to be unreachable following these events, various performance optimizations, specific to that object, become available.